<?php
function my_function_admin_bar(){
    return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');	

if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Categories',
		'before_widget' => '<div class="sidebar_box_top"></div><div class="sidebar_box">',
		'after_widget' => '</div><div class="sidebar_box_bottom"></div><div class="sidebar_box_sep"></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
    
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Latest Products',
		'before_widget' => '<div class="sidebar_box_top"></div><div class="sidebar_box">',
		'after_widget' => '</div><div class="sidebar_box_bottom"></div><div class="sidebar_box_sep"></div>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
	
	
function display_new_arrivals(){

query_posts( array('post__in'  => get_option('sticky_products'),
			'post_type' => 'wpsc-product',
			'numberposts' => 6));
			
			if (have_posts()) : while (have_posts()) : the_post(); ?>
			<li class='latest_product'>
			<a href="<?php the_permalink() ?>">
		 	<?php the_post_thumbnail('thumbnail', array('class' => 'product_image')); ?>
			<div class="product_info">
			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
			</div>	

		</li>
		<?php endwhile; endif; 
			

    }

	register_nav_menus( array(
		'primary' => __( 'Primary Navigation', 'wpstore2011' ),
	) );


$themename = "shopme2011";
$shortname = "shopme2011";


$options = array (

	
	
	array(	"name" => "A Very Very Short Intro Text",
			"type" => "title"),
			
	array(	"type" => "open"),
	
	array(	"name" => "Intro Text",
			"desc" => "Enter your Intro Text. please make it short (-:",
			"id" => $shortname."_introText",
			"std" => "",
			"type" => "text"),
			


	array(	"type" => "close"),
	
	
	array(	"name" => "New Arrivals Section - Homepage",
			"type" => "title"),
			
	array(	"type" => "open"),
	
	array(	"name" => "New Arrivals Section",
			"desc" => "Enter the title for this section, default is 'new arrivals'",
			"id" => $shortname."_hp_titleText",
			"std" => "",
			"type" => "text"),
			


	array(	"type" => "close"),	

	array(	"name" => "Your Carousel Promos <br> * first don't forget to upload some promo images to the wordpress media library. promo images should be width:590px AND height:194px",
			"type" => "title"),
			
	array(	"type" => "open"),
	
	array(	"name" => "promo1 url",
			"desc" => "Enter your promo1 URL.",
			"id" => $shortname."_promo1url",
			"std" => "",
			"type" => "text"),
			
	array(	"name" => "promo1 image full path",
			"desc" => "Enter your promo1 image full path.",
			"id" => $shortname."_promo1img",
			"std" => "",
			"type" => "text"),
			
			
	array(	"name" => "promo2 url",
			"desc" => "Enter your promo2 URL.",
			"id" => $shortname."_promo2url",
			"std" => "",
			"type" => "text"),
			
	array(	"name" => "promo2 image full path",
			"desc" => "Enter your promo2 image full path.",
			"id" => $shortname."_promo2img",
			"std" => "",
			"type" => "text"),	
			
			
	array(	"name" => "promo3 url",
			"desc" => "Enter your promo3 URL.",
			"id" => $shortname."_promo3url",
			"std" => "",
			"type" => "text"),
			
	array(	"name" => "promo3 image full path",
			"desc" => "Enter your promo3 image full path.",
			"id" => $shortname."_promo3img",
			"std" => "",
			"type" => "text"),						
	
	array(	"name" => "promo4 url",
			"desc" => "Enter your promo4 URL.",
			"id" => $shortname."_promo4url",
			"std" => "",
			"type" => "text"),
			
	array(	"name" => "promo4 image full path",
			"desc" => "Enter your promo4 image full path.",
			"id" => $shortname."_promo4img",
			"std" => "",
			"type" => "text"),			
			

	array(	"type" => "close")
	
	
	
	
	
);

function mytheme_add_admin() {

    global $themename, $shortname, $options;

    if ( $_GET['page'] == basename(__FILE__) ) {
    
        if ( 'save' == $_REQUEST['action'] ) {

                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

                foreach ($options as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }

                header("Location: themes.php?page=functions.php&saved=true");
                die;

        } else if( 'reset' == $_REQUEST['action'] ) {

            foreach ($options as $value) {
                delete_option( $value['id'] ); }

            header("Location: themes.php?page=functions.php&reset=true");
            die;

        }
    }

    add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');

}

function mytheme_admin() {

    global $themename, $shortname, $options;

    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
?>
<div class="wrap">
<h2><?php echo $themename; ?> settings</h2>

<form method="post">



<?php foreach ($options as $value) { 
    
	switch ( $value['type'] ) {
	
		case "open":
		?>
        <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
		
        
        
		<?php break;
		
		case "close":
		?>
		
        </table><br />
        
        
		<?php break;
		
		case "title":
		?>
		<table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
        	<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
        </tr>
                
        
		<?php break;

		case 'text':
		?>
        
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
        </tr>

        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php 
		break;
		
		case 'textarea':
		?>
        
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
            
        </tr>

        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php 
		break;
		
		case 'select':
		?>
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
       </tr>
                
       <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php
        break;
            
		case "checkbox":
		?>
            <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                        <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
                        </td>
            </tr>
                        
            <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
           </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
            
        <?php 		break;
	
 
} 
}
?>

<!--</table>-->

<p class="submit">
<input name="save" type="submit" value="Save changes" />    
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>

<?php
}

add_action('admin_menu', 'mytheme_add_admin'); ?>